<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>${model.comment}</title>
<%@ include file="/WEB-INF/views/mis/common_inc.jsp"%>
</head>
<style>
</style>
<body style="padding:0 10px;height:100%;overflow:hidden">
	<div class="main-div">
		<!-- 过滤条件 -->
		<div class="search-div">
			<form id="searchForm" method="get" class="layui-form">
			<blockquote class="layui-elem-quote news_search">
#foreach( $field in $fieldList )
#if(${field.matchType}=="any"||${field.matchType}=="eq"||${field.matchType}=="left"||${field.matchType}=="right")
	<div class="layui-inline">
		    &nbsp;&nbsp;&nbsp;${field.comment}
		    <div class="layui-input-inline">
		    	<input type="text" id="${field.field}" name="${field.field}" placeholder="请输入${field.comment}" class="layui-input search_input">
		    </div>
		</div>
#elseif(${field.matchType}=="select")
#if("$!field.inputValueOne" == "")
	<div class="layui-inline">
		    &nbsp;&nbsp;&nbsp;${field.comment}
		    <div class="layui-input-inline">
				<select id="${field.field}" name="${field.field}" style="display: none;"  lay-search="">
					<option value="">==请选择${field.comment}==</option>
		   			<my:outOptions code="${field.inputValue}" value=""/>
				</select>
		    </div>
	</div>
#else
	<div class="layui-inline">
		    &nbsp;&nbsp;&nbsp;${field.comment}
		    <div class="layui-input-inline">
				<select id="${field.field}" name="${field.field}" style="display: none;" lay-search="">
					<option value="">==请选择${field.comment}==</option>
					<c:forEach items="${${field.inputValueOneL}EntityList}" var="item">
					<option value="${ item.code }">${ item.${field.inputValueTwo}}</option>
					</c:forEach>
				</select>
		    </div>
	</div>
#end
#elseif(${field.matchType}=="numberRange")
		<div class="layui-inline">
		     &nbsp;&nbsp;&nbsp;${field.comment}范围
		    <div class="layui-input-inline">
                <input id="${field.field}_start" name="${field.field}_start" placeholder="开始${field.comment}" autocomplete="off" class="layui-input" type="text">
            </div>
            <div class="layui-input-inline">-</div>
            <div class="layui-input-inline">
                <input id="${field.field}_end" name="${field.field}_end" placeholder="结束${field.comment}" autocomplete="off" class="layui-input" type="text">
            </div>
		</div>
#elseif(${field.matchType}=="dateRange")
		<div class="layui-inline">
		     &nbsp;&nbsp;&nbsp;${field.comment}范围
		    <div class="layui-input-inline">
                <input id="${field.field}_start" name="${field.field}_start" placeholder="开始${field.comment}" onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD'})" value='<fmt:formatDate value="${${model.modelL}.${field.field}}" pattern="yyyy-MM-dd" />' class="layui-input" type="text">
            </div>
            <div class="layui-input-inline">-</div>
            <div class="layui-input-inline">
                <input id="${field.field}_end" name="${field.field}_end" placeholder="结束${field.comment}" onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD'})" value='<fmt:formatDate value="${${model.modelL}.${field.field}}" pattern="yyyy-MM-dd" />' class="layui-input" type="text">
            </div>
		</div>
#end
#end
		<div class="layui-inline">
			<a id="search_button" class="layui-btn search_btn layui-anim layui-anim-scaleSpring"  onClick="doSearch_dg()">查&nbsp;&nbsp;询</a>
		 
			<a class="layui-btn search_btn layui-anim layui-anim-scaleSpring"  onClick="doAdd_dg()">新增</a>
		</div>
	</blockquote>				
				
			</form>
		</div>
		<!-- 列表 -->
		<div class="grid-div">
			<table id="dg_table" ></table>
		</div>
	</div>

<script type="text/javascript">
var	dg_list=null;
layui.use('form', function(){
var form = layui.form();
form.render('select');
 form.render('checkbox');
});
$(function(){
	dg_list = $('#dg_table').datagrid(
			{
 				url : '${path}/${model.modelL}/list',
				method : 'get',
				pagination : true,
				pageSize:20,
				pageList:[10,20,30,50,100,200,300],
				fitColumns : true,
				border:false,//grid边框
				height:$("body").height()-$(".search-div").outerHeight()-10,//设置grid高度自适应页面高度
	            nowap: false, //列内容多时自动折至第二行
				sortName : 'CREATE_TIME', 
				sortOrder : 'desc',
				showFooter : false,
				remoteSort : true,
				loadFilter:function(d){ return d},//去掉json根目录匹配datagrid所需格式
				emptyMsg:"未查到数据",
				columns : [ [
				{field : 'code',hidden : true},
				//注意width属性的值不要加引号，如果加引号每次点击查询功能的时候单元格会自动拉宽
					{field:'index',title:'序号',width:20, align: 'center',formatter:function(val,row,index){
				     var options = $("#dg_table").datagrid('getPager').data("pagination").options; 
				     var currentPage = options.pageNumber;
				     var pageSize = options.pageSize;
				     return (pageSize * (currentPage -1))+(index+1);
				    }},  
#foreach( $field in $fieldList )
#if($field.listShow == true)
#if(${field.inputType}=="select"||${field.columnName}=='create_code'||${field.columnName}=='update_code')
            {
                width : 80,
                title : '${field.comment}',
                field : '${field.columnName}_name'
            },
#elseif(${field.inputType}=="date")
            {
                width : 80,
                title : '${field.comment}',
                field : '${field.columnName}',
                formatter : function(value, row,index) {
					var str = "";
					 str +=value.substring(0,10) ;
						 return str;
				}
				
            },
#elseif(${field.inputType}!="hidden")
            {
                width : 80,
                title : '${field.comment}',
                field : '${field.columnName}'
            },
#end
#end
#end
			{field:'action',title : '操作',align : 'center',width : 100,
				formatter : function(value, row,index) {
					var str = "";
					 str += "<a class='layui-btn layui-btn-mini layui-btn-normal' onclick='edit${model.model}(\""+row.code+"\")'>编辑</a>";
						str += "<a  class='layui-btn layui-btn-mini layui-btn-danger' onclick='delete${model.model}(\""+row.code+"\")'>删除</a>";
						str += "<a class='layui-btn layui-btn-mini layui-btn-normal' onclick='details${model.model}(\""+row.code+"\")'>详情</a>";
					return str;
				}
			} 	
		] ]
	});
	
});
//查询列表
$("#searchForm").keydown(function(e){
   if(e.keyCode==13){
	   doSearch_dg();
   }
});
function doSearch_dg(){
	dg_list.datagrid({url : '${path}/${model.modelL}/list',queryParams : form2Json("searchForm")});
}
function form2Json(id) {
	var arr = $("#" + id).serializeArray()
	var jsonStr = "";
	jsonStr += '{';
	for (var i = 0; i < arr.length; i++) {
		jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
	}
	jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	jsonStr += '}'

	var json = JSON.parse(jsonStr)
	return json
}
//新增
function doAdd_dg(){
	layer.open({
	  type: 2,
	  title: '新增',
	  shadeClose: false,
	  shade: 0.1,
// 	  skin:'layui-layer-molv',
	 	 area: ['40%', '60%'],
	  content: '${path}/${model.modelL}/add'
	}); 
}
 
//删除
function delete${model.model}(code){
	
	layer.confirm('是否删除？', {
		  btn: ['删除','取消'] //按钮
		}, function(){
			 $.post('${path}/${model.modelL}/delete?code='+code,function(data){
				data=$.parseJSON(data); 
				layer.close('dialog');
				layer.msg(data.message);
				doSearch_dg();
			});
		});
	 
}
//编辑
function edit${model.model}(code){
	layer.open({
	  type: 2,
	  title: '编辑',
	  shadeClose: false,
	  shade: 0.1,
// 	  skin:'layui-layer-molv',
		 area: ['40%', '60%'],
	  content: '${path}/${model.modelL}/edit?code='+code
	}); 
}
//查看详情
function details${model.model}(code){
	layer.open({
	  type: 2,
	  title: '详情',
	  shadeClose: false,
	  shade: 0.1,
// 	  skin:'layui-layer-molv',
	 	 area: ['40%', '60%'],
	  content: '${path}/${model.modelL}/detail?code='+code
	}); 
}
</script>
</body>
</html>